package offerv1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Offer06 {
    public int[] reversePrint(ListNode head) {
        //用栈存储节点
        List<Integer> list = new ArrayList<>();
        while (head != null) {
            list.add(head.val);
            head = head.next;
        }

        int size = list.size();
        int[] ret = new int[size];
        for (int i = 0; i < size; i++) {
            ret[i] = list.get(size - i - 1);
        }
        return ret;
    }
}

class ListNode {
    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
    }
}
